/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package makao;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import shared.Card;
import shared.MakaoPackage;
import shared.ThrowCards;

/**
 *
 * @author gekon
 */
public class PlayerAction
{

    private MakaoView makaoView = null;
    private ObjectOutputStream objectOutputStream = null;

    public PlayerAction(MakaoView makaoView, ObjectOutputStream objectOutputStream) throws IOException
    {
        this.makaoView = makaoView;
        this.objectOutputStream = objectOutputStream;
    }

    public void takeCard()
    {
        if (makaoView.getPlayerData().isMyTurn() == true)
        {
            try
            {
                objectOutputStream.writeObject(new MakaoPackage(MakaoPackage.GET_CARDS));
                objectOutputStream.flush();
            } catch (IOException ex)
            {
                Logger.getLogger(PlayerAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void waitTurns()
    {
        if (makaoView.getPlayerData().isMyTurn() == true)
        {
            try
            {
                objectOutputStream.writeObject(new MakaoPackage(MakaoPackage.WAIT_TURNS));
                objectOutputStream.flush();
            } catch (IOException ex)
            {
                Logger.getLogger(PlayerAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void throwCards(ArrayList<Card> cards)
    {
        if (makaoView.getPlayerData().isMyTurn() == true)
        {
            try
            {
                makaoView.getPlayerData().setThrownCards(cards);
                objectOutputStream.writeObject(new MakaoPackage(new ThrowCards(cards)));
                objectOutputStream.flush();
            } catch (IOException ex)
            {
                Logger.getLogger(PlayerAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void throwCardsDemandSuit(ArrayList<Card> cards, int demandSuit)
    {
        if (makaoView.getPlayerData().isMyTurn() == true)
        {
            try
            {
                makaoView.getPlayerData().setThrownCards(cards);
                objectOutputStream.writeObject(new MakaoPackage(new ThrowCards(cards, false, demandSuit)));
                objectOutputStream.flush();
            } catch (IOException ex)
            {
                Logger.getLogger(PlayerAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void throwCardsDemandType(ArrayList<Card> cards, int demandType)
    {
        if (makaoView.getPlayerData().isMyTurn() == true)
        {
            try
            {
                makaoView.getPlayerData().setThrownCards(cards);
                objectOutputStream.writeObject(new MakaoPackage(new ThrowCards(cards, true, demandType)));
                objectOutputStream.flush();
            } catch (IOException ex)
            {
                Logger.getLogger(PlayerAction.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}
